import urllib.request
def load_data():
    url = "http://www.199it.com/archives/760960.html"
    # get
    #  http响应对象;
    response = urllib.request.urlopen(url)
    print(response)
    # 读取内容 输出的类型 bytes 类型
    data = response.read()

    print(data)
    # 讲获取的内容 写入文件
    # 将 python3 bytes 转换成 字符串str
    str_data = data.decode('utf-8')
    with open('maikenxi.html', 'w',encoding="utf-8") as f:
        f.write(str_data)


    # 将 字符串str 转换成 bytes
    str_name = "麦肯锡数据中心"
    bytes_name = str_name.encode('utf-8')
    print(bytes_name)


    # python 类型  str  bytes
    #  如果爬取回来的是 bytes; 但是你写入的时候需要 字符串; decode('utf-8')
    #  如果爬取回来的是 str ;  但是你想要的 bytes;  encode('utf-8')

load_data()
